package com.ticket.sass.admin.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ticket.sass.admin.dto.input.pricescheme.PriceSchemeListInput;
import com.ticket.sass.admin.mapper.PriceSchemeMapper;
import com.ticket.sass.admin.service.BaseService;
import com.ticket.sass.common.entity.tenant.PriceSchemeEntity;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ywb
 * @since 2024-03-06
 */
@Service
public class PriceSchemeServiceImpl extends ServiceImpl<PriceSchemeMapper, PriceSchemeEntity> implements BaseService<PriceSchemeEntity> {
    /**
     * 根据条件查询价格方案列表
     * @param input 查询条件
     * @return 价格方案分页列表
     */
    public IPage<PriceSchemeEntity> iPage(PriceSchemeListInput input) {
        Page<PriceSchemeEntity> page = new Page<>(input.getPageNum(), input.getPageSize());
        QueryWrapper<PriceSchemeEntity> queryWrapper = buildQueryWrapper(this.entityClass, input);
        
        queryWrapper.orderByDesc("id");
        
        // 如果有效日期范围不为空，则添加范围查询条件
        if (input.getStartDate() != null && input.getEndDate() != null) {
            queryWrapper.between("start_date", input.getStartDate(), input.getEndDate());
            queryWrapper.between("end_date", input.getStartDate(), input.getEndDate());
        }

        // 执行分页查询并返回结果
        return this.page(page, queryWrapper);
    }

}
